<?php

namespace app\index\controller;

use addons\cardocr\library\Card;
use addons\cardocr\library\traits\Check;
use app\common\controller\Frontend;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\Request;

class Cardocr extends Frontend
{
    //引入检查类
    use Check;
    protected $layout = 'default';
    protected $noNeedRight = ['*'];

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->assignconfig("title", __("Tencent Identity Card Network Authentication"));
    }

    /**
     *
     * @return string
     */
    public function index()
    {
    }

    /** 身份证验证页面
     * @return string
     * @throws Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function docard()
    {
        $user_id = $this->auth->id;
        $data = \addons\cardocr\model\Cardocr::where('user_id', '=', $user_id)->find();
        $data = isset($data) ? $data->toArray() : array();
        $status = isset($data['status']) ? $data['status'] : 0;

        $username = isset($data['name']) ? Card::hidestr($data['name'], 0, -1) : "";

        $idnum = isset($data['idnum']) ? Card::hidestr($data['idnum'], 5, 9) : "";
        $positive_img = isset($data['positive_img']) ? $data['positive_img'] : "";
        $back_img = isset($data['back_img']) ? $data['back_img'] : "";

        $this->view->assign("status", $status);
        $this->view->assign("name", $username);
        $this->view->assign("idnum", $idnum);
        $this->view->assign("positive_img", $positive_img);
        $this->view->assign("back_img", $back_img);
        $this->assignconfig('checkstatus', $status);
        return $this->view->fetch();
    }



}
